package com.filldream.fastboot.core.job.task;

import com.filldream.fastboot.core.manager.CfAnnManager;
import com.filldream.fastboot.core.manager.CfArticleManager;
import com.filldream.fastboot.core.manager.CfNewsManager;
import com.filldream.fastboot.core.manager.CfReportManager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.*;

@Slf4j
@Service
@Component("EastCfTask")
@RequiredArgsConstructor
public class EastCfTask {

    private final CfArticleManager cfArticleManager;

    private final CfReportManager cfReportManager;

    private final CfAnnManager annManager;

    private final CfNewsManager cfNewsManager;

    /**
     * 刷新东财资讯
     */
    public void refreshArticle() {
        List<String> robotStockCode = cfArticleManager.getRobotStockCode();
        for (String stockCode : robotStockCode) {
            cfArticleManager.refreshArticle(stockCode);
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                log.error("同步东财资讯休眠异常", e);
                throw new RuntimeException(e);
            }
        }
        cfArticleManager.autoSendOwner(Arrays.asList("zr","sun"));
    }

    /**
     * 刷新东财研报
     */
    public void refreshReport() {
        List<String> robotStockCode = cfArticleManager.getRobotStockCode();
        for (String stockCode : robotStockCode) {
            cfReportManager.refreshReport(stockCode);
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                log.error("同步东财研报休眠异常", e);
                throw new RuntimeException(e);
            }
        }
        cfReportManager.autoSendOwner(Arrays.asList("zr","sun"));
    }

    /**
     * 刷新东财公告
     */
    public void refreshAnn() {
        List<String> robotStockCode = cfArticleManager.getRobotStockCode();
        for (String stockCode : robotStockCode) {
            annManager.refreshAnn(stockCode);
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                log.error("同步东财公告休眠异常", e);
                throw new RuntimeException(e);
            }
        }
        annManager.autoSendOwner(Arrays.asList("zr","sun"));
    }

    /**
     * 刷新东财新闻
     */
    public void refreshNews() {
        cfNewsManager.refreshNews();
        cfNewsManager.autoSendOwner(Arrays.asList("zr","sun"),false);
    }

}